package com.demo.testpackage;

import java.util.Arrays;

public class T3 {
    public static void main(String[] args) {
        int[] array = {23, 45, 545, 55, 675, 35, 988, 435, 999};
        Arrays.sort(array);
        Integer index = binarySearch(array, 35);
        System.out.println(index);
    }

    static int binarySearch(int[] array, int num) {
        int l = 0, r = array.length - 1, mid;
        while (l <= r) {
            mid = (l + r) >> 1;
            if (array[mid] == num) {
                return mid;
            } else if (array[mid] > num) {
                r = mid - 1;
            } else if (array[mid] < num) {
                l = mid + 1;
            }
        }
        return -1;
    }
}
